package com.stardata.liangshisq.tcslmon.config;

import com.stardata.liangshisq.tcslmon.entity.DbiEmp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author Samson Shu
 * @email shush@stardata.top
 * @date 2020/11/15 22:54
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

  //配置swagger的Docket的bean实例
  @Bean
  public Docket docket(Environment environment){

    //设置要显示的swagger环境
    Profiles profiles = Profiles.of("dev", "test");
    //通过environment.acceptsProfiles判断是否处于自己设定的环境中
    boolean flag = environment.acceptsProfiles(profiles);

    return new Docket(DocumentationType.SWAGGER_2)
        .groupName("default")
        .apiInfo(apiInfo())
        .enable(flag)
        .select()
        //配置要扫描的接口
        .apis(RequestHandlerSelectors.basePackage("com.stardata.liangshisq.tcslmon.controller"))
//        .paths(PathSelectors.ant("/users/**"))
        .build()
        .ignoredParameterTypes(DbiEmp.class);
  }

  //配置swagger信息=apiInfo
  private ApiInfo apiInfo(){

    //作者信息
    Contact contact = new Contact("Samson", "https://blog.csdn.net/hangsun", "shu.sh@163.com");

    return new ApiInfo(
        "粮食社区厨房出品管理系统API文档",
        "",
        "v1.0",
        "",
        contact,
        "Apache2.0",
        "",
        new ArrayList<>()
    );
  }
}
